package com.start.security.providers;

import com.start.common.constant.StartConstant;
import com.start.security.authentication.ManagerAuthenticationToken;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.stereotype.Component;

@Component
public class ManagerAuthenticationProvider extends DaoAuthenticationProvider {
    /**
     * 初始化 将使用Manager专用的userDetailsService
     * @param userDetailsService
     */
    public ManagerAuthenticationProvider(UserDetailsService userDetailsService){
        setPasswordEncoder(StartConstant.passwordEncoder);
        setUserDetailsService(userDetailsService);
    }



    /**
     * 判断只有传入ManagerAuthenticationToken的时候才使用这个Provider
     * supports会在AuthenticationManager层被调用
     * @param authentication
     * @return
     */
    public boolean supports(Class<?> authentication) {
        return ManagerAuthenticationToken.class.isAssignableFrom(authentication);
    }
}
